<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {
  
  public function index(){
		
      $this->display();
    }
	/*会员展示*/
	 public function home(){
		//echo ZHITUI;die;
		$Acc =  M('account');
		$data = I('post.user');
		
		if ($data <> '') {
            $map['account'] = $data;
			
        }
		$count = $Acc->where($map)->count(); 
		$p = getpage($count, 5);
		$list = $Acc->where($map)->order('jhtime')->limit($p->firstRow, $p->listRows)->select();
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['parid']))->find();
			$list[$k]['parid'] = $accpar['account'];
			if($v['zctime']){
				$list[$k]['zctime'] = date('Y-m-d H:i:s',$v['zctime']);
			}
			if($v['jhtime']){
				$list[$k]['jhtime'] =date('Y-m-d H:i:s', $v['jhtime']);
			}
			
			
		}
		$this->assign('list', $list);
		 $this->assign('page', $p->show());
		$this->display();
    }
	/*会员修改*/
	public function userxg(){
		if (I('get.user') <> '') {
			$user=I('get.user');
			/* $this->now=moth_dan($user);
			$this->last=last_moth($user);
			
			$this->zhicheng=zhicheng($user);*/

			$userdata = M('account')->where(array('id' => I('get.user')))->find(); 
			
            $this->userdata = $userdata; 

            if($userdata['level']==0){
                $this->mr0 = "selected = 'selected'";
            }
            if($userdata['level']==1){
                $this->mr1 = "selected = 'selected'";
            }
            if($userdata['level']==2){
                $this->mr2 = "selected = 'selected'";
            }
            if($userdata['level']==3){
                $this->mr3 = "selected = 'selected'";
            }
            if($userdata['level']==4){
                $this->mr4 = "selected = 'selected'";
            }
            if($userdata['level']==5){
                $this->mr5 = "selected = 'selected'";
            }
            
			
            $this->display();
        } else {
            $this->error('非法操作!');
        }
	}
	
	/*会员修改*/
	  public function usercl()
    {
		
		//dump(I('post.'));die;
		 $data['account'] = I('post.account');
		  $data['phone'] = I('post.phone');
		  if(I('post.firstpwd')){
			  // $data['firstpwd'] =  myencode(I('post.firstpwd'),5,5);
			  $data['firstpwd'] =  $this->md5pw(I('post.firstpwd'));
		  }
		  if(I('post.secpwd')){
			 // $data['secpwd'] =  myencode(I('post.secpwd'),5,5);
			 $data['secpwd'] =  $this->md5pw(I('post.secpwd'));
		  }
		   if(I('post.thirpwd')){
			 // $data['thirpwd'] =  myencode(I('post.thirpwd'),5,5);
			 $data['thirpwd'] =  $this->md5pw(I('post.thirpwd'));
		  }
		  
		   
		    
        $mrlevel = I('post.mrlevel');
        $xlevel = I('post.level');
        if($mrlevel!=$xlevel){
        	if($mrlevel<2 && $xlevel>1){
        		$data['daitime'] = time();
        	}
        	$data['level'] = I('post.level');
        }
        
        $data['cart_id'] = I('post.cart_id');//身份证
        $data['bank_name'] = I('post.bank_name');
        $data['bank_num'] = I('post.bank_num');
        $data['bank_zhi'] = I('post.bank_zhi');
        $data['province'] = I('post.province');
		
        if(M('account')->where(array('id' => I('post.hid')))->save($data)) {
            $this->success('修改成功!');
        } else {
            $this->success('修改失败!');
        } 
    }

    /**
     * 密码加密
     */
    function md5pw($passwd)
    {
        $ph = new \Think\PasswordHash();
        return $ph->HashPassword($passwd);

    }
	
	public function userdel(){
		
		$User = M('account'); // 實例化User對象
        $id = I('get.user');
        $userxx = $User->where(array('id' => $id))->find();
		
        if ($id <> '' && $userxx['name'] <> '') {
            $User->where(array('id' => $id))->delete();
            $this->success('删除成功!');
        } else {
            $this->error('错误操作!');
        }
		
	}

	public function useradd(){

        
        $this->display();
    }

    public function user_add(){

        $data['zctime'] = time();//注册时间

        $data['account'] = I('post.account');
        if(empty($data['account'])){

            die("<script>alert('请填写会员账号!');history.back(-1);</script>");

        }
        $user=M('account')->where(array('account' => $data['account']))->find();
        if(!empty($user)){

            die("<script>alert('该会员账号已存在，请换一个试试!');history.back(-1);</script>");

        }
        $data['name'] = I('post.name');
        if(empty($data['name'])){

            die("<script>alert('请填写真实姓名!');history.back(-1);</script>");

        }
        $data['email'] = I('post.email');
        // if(empty($data['email'])){

        //     die("<script>alert('请填写邮箱!');history.back(-1);</script>");

        // }
        if(I('post.email')){
            // if (!preg_match ( ' /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',$data['email'] )) {
            if (!preg_match ( ' /^\w+((-\w+)|(\.\w+))*\@[0-9a-zA-Z]+((-|\.)[0-9a-zA-Z]+)*\.[0-9a-zA-Z]+$/',I('post.email') )) {
                die("<script>alert('邮箱格式不对!');history.back(-1);</script>");
            }
        }
        $data['phone'] = I('post.phone');
        if(empty($data['phone'])){

            die("<script>alert('请填写手机号码!');history.back(-1);</script>");

        }
        if (I('post.phone')) {
            //正则表达式匹配
            if (!preg_match ( ' /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))\\d{8})$/',I('post.phone') )) {
                die("<script>alert('手机格式不对!');history.back(-1);</script>");
            }
        }
        $data['investmoney'] = I('post.investmoney');
        // if(empty($data['investmoney'])){

        //     die("<script>alert('请填写投资金额!');history.back(-1);</script>");

        // }
        // if(($data['investmoney']<1000) || ($data['investmoney']>30000) || ($data['investmoney'] % 1000 >0)){

        //     die("<script>alert('投资金额1000~30000,且必须是1000的倍数!');history.back(-1);</script>");

        // }
        $setting=M('setting')->where('id=1')->find();
    if(I('post.investmoney')){
        if(($data['investmoney']<$setting['min_money']) || ($data['investmoney']>$setting['max_money']) || ($data['investmoney'] % $setting['bei_money'] >0)){

            // die("<script>alert('投资金额1000~30000,且必须是1000的倍数!');history.back(-1);</script>");
            die("<script>alert('投资金额".$setting['min_money']."~".$setting['max_money'].",且必须是".$setting['bei_money']."的倍数!');history.back(-1);</script>");

        }
    }else{
    	$data['level'] = 0;
    }
        if($data['investmoney']>0 && $data['investmoney']<5000){
            $data['level'] = 1;
        }
        if($data['investmoney']>=5000 && $data['investmoney']<10000){
            $data['level'] = 3;
        }
        if($data['investmoney']>=10000 && $data['investmoney']<20000){
            $data['level'] = 4;
        }
        if($data['investmoney']>=20000 && $data['investmoney']<=30000){
            $data['level'] = 5;
        }
        // if($data['investmoney']>=30000){
        //     $data['level'] = 6;
        // }
        // if($data['level']>1){
        //     $data['daitime'] = time();//成为代理的时间
        // }
        

        if(!I('post.firstpwd')){

            die("<script>alert('请填写一级密码!');history.back(-1);</script>");

        }
        if(!I('post.qr_firstpwd')){

            die("<script>alert('请填写确认一级密码!');history.back(-1);</script>");

        }
        $firstpwd = I('post.firstpwd');
        $qr_firstpwd = I('post.qr_firstpwd');

        if($firstpwd<>$qr_firstpwd){

            die("<script>alert('填写的一级密码和确认一级密码不一致!');history.back(-1);</script>");

        }
        $data['firstpwd'] = $this->md5pw(I('post.firstpwd'));

        
        if(!I('post.secpwd')){

            die("<script>alert('请填写二级密码!');history.back(-1);</script>");

        }
        if(!I('post.qr_secpwd')){

            die("<script>alert('请填写确认二级密码!');history.back(-1);</script>");

        }
        $secpwd = I('post.secpwd');
        $qr_secpwd = I('post.qr_secpwd');
        if($secpwd<>$qr_secpwd){

            die("<script>alert('填写的二级密码和确认二级密码不一致!');history.back(-1);</script>");

        }
        $data['secpwd'] = $this->md5pw(I('post.secpwd'));

        
        if(!I('post.thirpwd')){

            die("<script>alert('请填写三级密码!');history.back(-1);</script>");

        }
        if(!I('post.qr_thirpwd')){

            die("<script>alert('请填写确认三级密码!');history.back(-1);</script>");

        }
        $thirpwd = I('post.thirpwd');
        $qr_thirpwd = I('post.qr_thirpwd');
        if($thirpwd<>$qr_thirpwd){

            die("<script>alert('填写的三级密码和确认三级密码不一致!');history.back(-1);</script>");

        }
        $data['thirpwd'] = $this->md5pw(I('post.thirpwd'));

        $tjr = I('post.tjr');
        // if(!I('post.tjr')){

        //     die("<script>alert('请填写推荐人账户名!');history.back(-1);</script>");

        // }
    if(I('post.tjr')){
        $tjruser=M('account')->where(array('account' => $tjr))->find();
        if(!$tjruser){

            die("<script>alert('填写的推荐人账户名不存在，请重新填写!');history.back(-1);</script>");

        }
        $data['parid'] = $tjruser['id'];
    }

        
        $data['mbwt'] = I('post.mbwt');
        $data['mbdan'] = I('post.mbdan');
        if(!I('post.mbwt')){

            die("<script>alert('请选择密保问题!');history.back(-1);</script>");

        }
        if(!I('post.mbdan')){

            die("<script>alert('请填写密保答案!');history.back(-1);</script>");

        }
        if(!I('post.cart_id')){

            die("<script>alert('请填写身份证号!');history.back(-1);</script>");

        }
        $data['cart_id'] = I('post.cart_id');

        // if(!I('post.province')){

        //     die("<script>alert('请填写省·市·地区详细地址!');history.back(-1);</script>");

        // }
        $data['province'] = I('post.province');

        if(!I('post.bank_username')){

            die("<script>alert('请填写开户姓名!');history.back(-1);</script>");

        }
        $data['bank_username'] = I('post.bank_username');

        if(!I('post.bank_num')){

            die("<script>alert('请填写银行卡号!');history.back(-1);</script>");

        }
        $data['bank_num'] = I('post.bank_num');

        if(!I('post.bank_name')){

            die("<script>alert('请填写开户行!');history.back(-1);</script>");

        }
        $data['bank_name'] = I('post.bank_name');

        if(!I('post.bank_zhi')){

            die("<script>alert('请填写支行信息!');history.back(-1);</script>");

        }
        $data['bank_zhi'] = I('post.bank_zhi');

        $jhzt=I('post.jhzt');
        if(I('post.jhzt')){
        	if($jhzt==1){
        		$data['status'] = 1;//默认激活
        		$data['jhtime'] = time();//激活时间
        		if($data['level']>1){
                    $data['daitime'] = time();//成为代理的时间
                }

                if(I('post.tjr')){
                    if(I('post.investmoney')){

                        //计算推荐奖
                        $numpri = $data['investmoney']*ZHITUI;
        
                        $prantqq = M('account')->where(array('id'=>$data['parid']))->find();

                        if($prantqq){
                            $newzhi = $prantqq['zhitui']+$numpri;
                            $prant = M('account')->where(array('id'=>$data['parid']))->save(array('zhitui'=>$newzhi));
                            $title='推荐'.$data['account'].'所得推荐奖励';
                            $D=M('reward');
                            $arr=array(
                                'uid'=>$data['parid'],
                                'title'=>$title,
                                'money'=>$numpri,
                                'times_c'=>time(),
                                'typemoney'=>2,
                            );
                            $D->add($arr);
                        }
                    }
                }

        	}
        	if($jhzt==2){
        		$data['status'] = 0;//默认未激活
        	}


        }else{
        	die("<script>alert('请选择激活状态!');history.back(-1);</script>");
        }

        $reg=M('account')->add($data);//生成新会员

        if($reg){
            echo"<script>alert('注册成功!');location.href='/Admin/Index/home'</script>";
            
        }else{
            
            echo"<script>alert('注册失败!');location.href='/Admin/Index/useradd'</script>";
        }


        
    }


	/*
	
	展示管理员
	*/
	public function member(){
		
		$Member =  M('member');
		$data = I('post.');
		
		if ($data <> '') {
            $map['name'] = $data;
			
        }
		$count = $Member->count(); 
		$p = getpage($count, 20);
		$list = $Member->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		$this->assign('list', $list);
		 $this->assign('page', $p->show()); 
		$this->display();
		
	}
	
	/*增加后台管理员*/
	public function addmember()
	{
		$data = I('post.');
		if($data){
			//dump($data);
			$data['name'] = I('post.name');//身份证
			$data['pwd'] = myencode(I('post.pwd'),5,5);
			$data['email'] = I('post.email');
			$data['note'] = I('post.note');
			$data['status'] = I('post.inlineRadioOptions');

			if(M('member')->add($data)) {
				$this->success('添加管理员成功!');
			} else {
				$this->success('添加失败，请重新添加!');
			}  
		}else{
			
			$this->display();
		} 
		
	}
	/*修改管理员*/
	
	public function memberxg()
	{
		
		$id = I('get.id');
		if($id){
			//dump($data);
			$this->memberdata = M('member')->where(array('id' => I('get.id')))->find(); 
			$this->display();
		}
		if(IS_POST){
				$data['name'] = trim($_POST['name']);
				$data['pwd'] = myencode($_POST['pwd'],5,5);
				$data['email'] = trim($_POST['email']);
				$data['note'] = trim($_POST['note']);
				$data['inlineRadioOptions'] = trim($_POST['inlineRadioOptions']);
				//echo  $_POST['hid'];
				if(M('member')->where(array('id'=> $_POST['hid']))->save($data)){
					
				$this->success('修改成功!');
				// redirect(site_url('Index/news'));
			  } 
			}
	}
	
	
	public function memberdel(){
		
		$User = M('member'); // 實例化User對象
        $id = I('get.id');
        $userxx = $User->where(array('id' => $id))->find();
		
        if ($id <> '' && $userxx['name'] <> '') {
            $User->where(array('id' => $id))->delete();
            $this->success('删除成功!');
        } else {
            $this->success('公司账号不能删除!');
        }
		
	}
	
	/*投资管理*/
	
	public function invest(){
		
		$Invest =  M('invest');
		$Acc = M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND times >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  times <= '".strtotime(trim($_GET['end_time']) )." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Invest->count(); 
		$p = getpage($count, 20);
		$list = $Invest->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['uid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['name'] = $accpar['name'];
			$list[$k]['times'] = date('Y-m-d H:i:s',$v['times']);
		}
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	
	
	/**/
	public function is_yes() {
		$id = $_POST['id'];
		$Account = M('account');
		 $Invest = M('invest');
		 if ($id) {
			// if ($_SERVER['HTTP_REFERER'] != site_url('Index/admin_coin')) {
				// echo json_encode(array('message'=>'参数错误'));exit();
			// }
			/*if ($this->user_id != 1) {
				echo json_encode(array('message'=>'权限错误'));exit();
			}*/
			$r = M('invest')->where('id = ' . $id)->find();
			if (!$r) {
				echo json_encode(array('message'=>'参数错误'));exit();
			}
			if ($r['status'] != 0) {
				echo json_encode(array('message'=>'操作失败，请核对订单状态'));exit();
			}
			$num = $r['inmoney'];
			$level =  $Account->where(array('id'=>$r['uid']))->find();
			$rt =  $Invest->where(array('id'=>$id))->save(array('status'=>1,'oktimes'=>time()));//修改订单状态
			$new_investmoney = $level['investmoney']+$num;
			$tt = $Account->where(array('id'=>$r['uid']))->save(array('investmoney'=>$new_investmoney));//增加到会员投资额

            if($level['parid']){

                $numpri = $num*ZHITUI;

                $prantqq = $Account->where(array('id'=>$level['parid']))->find();

                $newzhi = $prantqq['zhitui']+$numpri;
                $prant = $Account->where(array('id'=>$level['parid']))->save(array('zhitui'=>$newzhi));
                $title=$level['account'].'投资所得推荐奖励';
                $D=M('reward');
                $arr=array(
                    'uid'=>$level['parid'],
                    'title'=>$title,
                    'money'=>$numpri,
                    'times_c'=>time(),
                    'typemoney'=>2,
                );
                $D->add($arr);

            }

            
			
			//判断会员等级
			

			$hh = level($level['level'],$new_investmoney,$r['uid']);
			
			//echo json_encode(array('message'=>$tt));exit();
			if($tt && $rt){
				echo json_encode(array('message'=>'操作成功！'));exit();
			}else{
				echo json_encode(array('message'=>'操作失败！'));exit();
			}
			
			
		} 
	}
	/*激活账号*/
	
	public function is_jihuo() {
		$id = $_POST['id'];
		$Account = M('account');
		$judge = $Account->where(array('id'=>$id))->find();
		
		//计算推荐奖
		$numpri = $judge['investmoney']*ZHITUI;
		
		$prantqq = $Account->where(array('id'=>$judge['parid']))->find();

		if($prantqq){
			$newzhi = $prantqq['zhitui']+$numpri;
		    $prant = $Account->where(array('id'=>$judge['parid']))->save(array('zhitui'=>$newzhi));
		    $title='推荐'.$judge['account'].'所得推荐奖励';
		    $D=M('reward');
            $arr=array(
                'uid'=>$judge['parid'],
                'title'=>$title,
                'money'=>$numpri,
                'times_c'=>time(),
                'typemoney'=>2,
            );
            $D->add($arr);
		}
		
		//是否要升级
		
		if($judge['level']<=1){
			$rt =  $Account->where(array('id'=>$id))->save(array('status'=>1,'jhtime'=>time()));
		}else{
			$rt =  $Account->where(array('id'=>$id))->save(array('status'=>1,'jhtime'=>time(),'daitime'=>time()));
		}
		
		
		
		
		
		if( $rt ){
				echo json_encode(array('message'=>'操作成功！'));exit();
			}else{
				echo json_encode(array('message'=>'操作失败！'));exit();
			}
		
		
	}
	
	
	/*退单审核*/
	public function is_shenhe() {
		$id = $_POST['id'];
		$Account = M('account');
		$Tuidan = M('tuidan');
		 if ($id) {
			
			$r = M('tuidan')->where('id = ' . $id)->find();
			if (!$r) {
				echo json_encode(array('message'=>'参数错误'));exit();
			}
			if ($r['status'] == 2) {
				echo json_encode(array('message'=>'操作失败，请核对订单状态'));exit();
			}
			$num = $r['cashmoney'];
			$level =  $Account->where(array('id'=>$r['userid']))->find();
			if($level){
				$rt =  $Tuidan->where(array('id'=>$id))->save(array('status'=>2));//修改退单状态到已审核
				$new_cashmoney = $level['cashmoney']-$num;
				
				
				$tt = $Account->where(array('id'=>$r['userid']))->save(array('investmoney'=>0,'cashmoney'=>$new_cashmoney,'status'=>2,));//更新会员钱包和状态到冻结状态
				//echo json_encode(array('message'=>$tt));exit();
				
				
				
				if($tt && $rt ){
					echo json_encode(array('message'=>'操作成功！'));exit();
				}else{
					echo json_encode(array('message'=>'操作失败！'));exit();
				}
			}else{
				echo json_encode(array('message'=>'账号信息错误！'));exit();
			}
			
			
			
		} 
	}
	/*升级为代理*/
	public function is_agent() {
		$id = $_POST['id'];
		$Account = M('account');
		$Upgrade = M('upgrade');
		 if ($id) {
			
			$r = M('upgrade')->where('id = ' . $id)->find();
			if (!$r) {
				echo json_encode(array('message'=>'参数错误'));exit();
			}
			if ($r['status'] == 1) {
				echo json_encode(array('message'=>'操作失败，请核对申请状态'));exit();
			}
			$num = $r['cashmoney'];
			$level =  $Account->where(array('id'=>$r['userid']))->find();
			if($level){
				$rt =  $Upgrade->where(array('id'=>$id))->save(array('status'=>1));//
				
				if($level['level']<2){
					
					$map['level']=2;
					$map['daitime']=time();
				}else{
					
					$map['level']=$level['level'];
				}
				$tt = $Account->where(array('id'=>$r['userid']))->save($map);//
				//echo json_encode(array('message'=>$tt));exit();
				if($tt && $rt ){
					echo json_encode(array('message'=>'操作成功！'));exit();
				}else{
					echo json_encode(array('message'=>'操作失败！'));exit();
				}
			}else{
				echo json_encode(array('message'=>'账号信息错误！'));exit();
			}
			
			
			
		} 
	}
	/*提现审核*/
	public function is_tixian() {
		$id = $_POST['id'];
		$Account = M('account');
		$Tixing = M('tixing');
		 if ($id) {
			
			$r = M('tixing')->where('id = ' . $id)->find();
			if (!$r) {
				echo json_encode(array('message'=>'参数错误'));exit();
			}
			if ($r['status'] == 1) {
				echo json_encode(array('message'=>'操作失败，请核对申请状态'));exit();
			}
			
				$rt =  $Tixing->where(array('id'=>$id))->save(array('status'=>1));//修改退单状态到已审核
				

				//echo json_encode(array('message'=>$tt));exit();
				if( $rt ){
					echo json_encode(array('message'=>'操作成功！'));exit();
				}else{
					echo json_encode(array('message'=>'操作失败！'));exit();
				}
			
			
			
			
		} 
	}
	
	
	
	/**/
	public function invest_delete() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('invest')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		if ($r['status'] == 1) {
			echo json_encode(array('message'=>'操作失败，请核对订单状态'));exit();
		}
		$fd = M('invest')->where(array('id'=>$id))->delete();
		echo json_encode(array('message'=>'操作成功！'));exit();
		// redirect($_SERVER['HTTP_REFERER']);
	}
	
	
	public function setting() {
		if ($_POST){
//			$data['bank_num']  = trim($_POST['bank_num']);
//			$data['bank_name']  = trim($_POST['bank_name']);
//			$data['bank_username']  = trim($_POST['bank_username']);
//			$data['bank_zhi']  = trim($_POST['bank_zhi']);
			
//			$data['min_money']  = trim($_POST['min_money']);
//			$data['max_money']  = trim($_POST['max_money']);
//			$data['bei_money']  = trim($_POST['bei_money']);
			$data['rate']       = trim($_POST['rate']);
//			$data['zhitui']     = trim($_POST['zhitui']);
			$data['zt_txmoney'] = trim($_POST['zt_txmoney']);
			$data['zt_txbei']   = trim($_POST['zt_txbei']);
			$data['agent_money']= trim($_POST['agent_money']);
			$data['txtime1']    = trim($_POST['txtime1']);
			$data['txtime2']    = trim($_POST['txtime2']);
			$data['txmoney'] 	= trim($_POST['txmoney']);
			$data['txbei']   	= trim($_POST['txbei']);
			
			$data['status']  	= trim($_POST['status']);
			
			$data['cash']       = trim($_POST['cash']);
			$data['zhi']  	    = trim($_POST['zhi']);
			$data['year']    	= trim($_POST['year']);
			$data['half']  	    = trim($_POST['half']);

			$data['service_charge'] = trim($_POST['service_charge']);

			$data['register_coin'] = trim($_POST['register_coin']);
			$data['order_coin'] = trim($_POST['order_coin']);

			$data['cash_percent'] = trim($_POST['cash_percent']);
			$data['order_percent'] = trim($_POST['order_percent']);
			$data['stock_percent'] = trim($_POST['stock_percent']);
			$data['re_cast_percent'] = trim($_POST['re_cast_percent']);
			
			//echo json_encode(array('message'=>$data['cash'] ));exit();
			/*$file = $_FILES['logofile'];
		
			$picqu = $this->db->where('id', 1)->get('sys')->row_array();
				
			if($file['name']<> ''){
				$data['pic'] = $file['name'];
				$upload_path = "./uploads/logo/";
				move_uploaded_file($file['tmp_name'],$upload_path.$file['name']);
			}else{
				$data['pic'] = $picqu['pic'];
			}*/
			if(M('setting')->where(array('id'=>1))->save($data)) {
				echo json_encode(array('message'=>'配置成功'));exit();
			} else {
				echo json_encode(array('message'=>'配置失败'));exit();
			}
		}
		$set = M('setting')->where(array('id'=>1))->find();
		$this->assign('set', $set);
		$this->display();
	}
	public function bank_set() {
		if ($_POST){
			$data['bank_num']  = trim($_POST['bank_num']);
			if(empty($_POST['bank_num'])){

                die("<script>alert('请填写银行卡号!');history.back(-1);</script>");

            }
            if (!preg_match ( ' /^(\d{16}|\d{19})$/',$_POST['bank_num'] )){

                die("<script>alert('银行卡号格式不对!');history.back(-1);</script>");
            }
			$data['bank_name']  = trim($_POST['bank_name']);
			$data['bank_username']  = trim($_POST['bank_username']);
			$data['bank_zhi']  = trim($_POST['bank_zhi']);
			$data['userid']  = '0';
//echo json_encode(array('message'=>$data['bank_zhi']));exit();
			
			if(M('bank')->add($data)) {
				echo json_encode(array('message'=>'配置成功'));exit();
			} else {
				echo json_encode(array('message'=>'配置失败'));exit();
			}
		}
		
		$where = '1 =1';
		$where .= ' and userid = 0';
		 $Bank = M('bank');
		$count = $Bank->count(); 
		$p = getpage($count, 20);
		$set = $Bank->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		
		
		//$set = M('bank')->where(array('userid'=>'0'))->select();
		$this->assign('set', $set);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	/*银行*/
	public function bankset() {
		
		$id = I('get.gf');
		$Bank =  M('bank');
		$bank = $Bank->where(array('id'=>$id))->find();
		
		$this->assign('bank', $bank);
		//dump($id);
		$this->display();
	}
	/*修改银行*/
	public function bankxg() {
		
		if ($_POST['bank_num'] && $_POST['bank_name']) {
			$data['bank_num']  = trim($_POST['bank_num']);
			$data['bank_name']  = trim($_POST['bank_name']);
			$data['bank_username']  = trim($_POST['bank_username']);
			$data['bank_zhi']  = trim($_POST['bank_zhi']);
			
			if (M('bank')->where(array('id'=>$_POST['hid']))->save($data)) {
				echo json_encode(array('message'=>'修改成功'));exit();
				// redirect(site_url('Index/news'));
			} else {
				echo json_encode(array('message'=>'修改失败'));exit();
				
			}
		}else{
			echo json_encode(array('message'=>'请重新填写与核对'));exit();
		}
		
	}
	/*删除银行*/
	public function del_bank() {
		$id = $_POST['id'];
		
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$r = M('bank')->where(array('id'=>$id))->find();
		//echo json_encode(array('message'=>$id));exit();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('bank')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		
	}
	/**/
	public function news() {
		
		if ($_POST['title'] && $_POST['content']) {
			$data['title'] = trim($_POST['title']);
			$data['content'] = trim($_POST['content']);
			$data['createtime'] = time();
			if (!$data['title']) {
				echo json_encode(array('message'=>'标题不能为空'));exit();
				// $this->show_msg('标题不能为空!');
			}
			if (M('news')->add($data)) {
				echo json_encode(array('message'=>'发布成功！'));exit();
				// redirect(site_url('Index/news'));
			} else {
				echo json_encode(array('message'=>'发布失败'));exit();
				// $this->show_msg('发布失败，请重试!');
			}
		}
		$where = '1 =1';
		 $News = M('news');
		$count = $News->count(); 
		$p = getpage($count, 20);
		$news = $News->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		
		foreach($news as $k=>$v){
			$news[$k]['creatime'] = date('Y-m-d H:i:s',$v['createtime']);
		}
		$this->assign('news', $news);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	/*查看新闻*/
	public function news_info() {
		
		$id = I('get.gf');
		$News =  M('news');
		$news = $News->where(array('id'=>$id))->find();
		
		$this->assign('news', $news);
		//dump($id);
		$this->display();
	}
	/*修改新闻*/
	public function newsxg() {
		
		if ($_POST['title'] && $_POST['content']) {
			$data['title'] = trim($_POST['title']);
			$data['content'] = trim($_POST['content']);
			$data['createtime'] = time();
			if (!$data['title']) {
				echo json_encode(array('message'=>'标题不能为空'));exit();
				// $this->show_msg('标题不能为空!');
			}
			if (M('news')->where(array('id'=>$_POST['hid']))->save($data)) {
				echo json_encode(array('message'=>'修改成功'));exit();
				// redirect(site_url('Index/news'));
			} else {
				echo json_encode(array('message'=>'修改失败'));exit();
				// $this->show_msg('发布失败，请重试!');
			}
		}else{
			echo json_encode(array('message'=>'请重新填写与核对'));exit();
		}
		
	}
	/*删除新闻*/
	public function del_news() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('news')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('news')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	
	/*退单*/
	public function tuidan(){
		
		$Tuidan =  M('tuidan');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND sqtime >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  sqtime <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Tuidan->count(); 
		$p = getpage($count, 20);
		$list = $Tuidan->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['userid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['sqtime'] = date('Y-m-d H:i:s',$v['sqtime']);
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	public function tuidan_delete() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('tuidan')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('tuidan')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	
	/*代理费*/
	public function agent(){
		
		$Upgrand =  M('upgrade');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND jstime >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  jstime <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Upgrand->count(); 
		$p = getpage($count, 20);
		$list = $Upgrand->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['userid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['jstime'] = date('Y-m-d H:i:s',$v['jstime']);
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	public function agent_delete() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('upgrade')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('upgrade')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	public function tixing_delete() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('tixing')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('tixing')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	public function transfer_delete() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('transfer')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('transfer')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	/*提现记录*/
	public function tixing(){
		
		$Tixing =  M('tixing');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND txtime >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  txtime <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Tixing->count(); 
		$p = getpage($count, 20);
		$list = $Tixing->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['userid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['txtime'] = date('Y-m-d H:i:s',$v['txtime']);
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	/*转账记录*/
	public function transfer(){
		
		$Transfer =  M('transfer');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND zhtime >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  zhtime <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Transfer->count(); 
		$p = getpage($count, 20);
		$list = $Transfer->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['userid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['zhtime'] = date('Y-m-d H:i:s',$v['zhtime']);
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	/*复投记录*/
	public function redelivery(){
		
		$Redelivery =  M('redelivery');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND createtime >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  createtime <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Redelivery->count(); 
		$p = getpage($count, 20);
		$list = $Redelivery->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['userid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	
	/*复投删除*/
	public function del_redelivery() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('redelivery')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('redelivery')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	/*复投记录*/
	public function reward(){
		
		$Reward =  M('reward');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND times_fa >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  times_fa <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Reward->count(); 
		$p = getpage($count, 20);
		$list = $Reward->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['uid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['times_fa'] = date('Y-m-d H:i:s',$v['times_fa']);
			$list[$k]['times_c'] = date('Y-m-d H:i:s',$v['times_c']);
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	
	/*复投删除*/
	public function del_reward() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('reward')->where('id = ' . $id)->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('reward')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	
	/*留言记录*/
	public function message(){
		
		$Message =  M('message');
		$Acc =  M('account');
		$where = '1 = 1';
		if ($_GET['start_time'] && $_GET['end_time']) {
			
			$where .= " AND time >= '".strtotime(trim($_GET['start_time']))." 00:00:00' AND  time <= '".strtotime(trim($_GET['end_time'])) ." 23:59:59'";
			$s1 = trim($_GET['start_time']);
			$s2 = trim($_GET['end_time']);
			$this->assign('s1', $s1);
			$this->assign('s2', $s2);
			
		}
		/*if ($_GET['key']) {
			
			$where .= " AND (order_sn like '%".trim($_GET['key'])."%' or name like '%".trim($_GET['key'])."%' or order_sn like '%".trim($_GET['key'])."%')";
			$s0 = $_GET['key'];
			$this->assign('s0', $s0);
		}*/
		$count = $Message->count(); 
		$p = getpage($count, 20);
		$list = $Message->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
		
		foreach($list as $k=>$v){
			$accpar = $Acc->where(array('id'=>$v['userid']))->find();
			$list[$k]['account'] = $accpar['account'];
			$list[$k]['time'] = date('Y-m-d H:i:s',$v['time']);
			
		}
		//dump($list);die;
		$this->assign('list', $list);
		$this->assign('page', $p->show()); 
		$this->display();
	}
	
	/*查看留言*/
	public function meg(){
		$id = I('get.yy');
		$Message =  M('message');
		$meg = $Message->where(array('id'=>$id))->find();
		if($meg['status'] == 0){
			// $hfmeg = $Message->where(array('id'=>$id))->save(array('status'=>'1'));
			$hfmeg = $Message->where(array('id'=>$id))->save(array('status'=>'0'));
		}
		
		$this->assign('meg', $meg);
		$this->display();
		
		
	}
	public function hfmeg(){
		$id = I('get.hf');
		$Message =  M('message');
		$meg = $Message->where(array('id'=>$id))->find();
		$this->assign('meg', $meg);
		$this->display();
		
		
	}
	public function hfmegs(){
		$id = $_POST['hid'];
		$Message =  M('message');
		$meg = $Message->where(array('id'=>$id))->find();
		
		if($meg){
			// $hfmeg = $Message->where(array('id'=>$id))->save(array('hfcontent'=>$_POST['hfcontent'],'status'=>'2'));
			$hfmeg = $Message->where(array('id'=>$id))->save(array('hfcontent'=>$_POST['hfcontent'],'status'=>'1'));
			
			if($hfmeg){
				echo json_encode(array('message'=>'回复成功'));exit();
			}else{
				echo json_encode(array('message'=>$_POST['hfcontent']));exit();
			}
		}else{
			echo json_encode(array('message'=>'读取错误'));exit();
		}
		
		
		
	}
	
	/*删除留言*/
	
	public function del_meg() {
		$id = $_POST['id'];
		if (!intval(abs($id))) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		//权限检测
		/*if ($this->user_id != 1) {
			echo json_encode(array('message'=>'您无此权限'));exit();
		}*/
		$r = M('message')->where(array('id'=>$id))->find();
		if (!$r) {
			echo json_encode(array('message'=>'参数错误'));exit();
		}
		
		$fd = M('message')->where(array('id'=>$id))->delete();
		if($fd){
			echo json_encode(array('message'=>'操作成功！'));exit();
		}else{
			echo json_encode(array('message'=>'操作失败！'));exit();
		}
		
		// redirect($_SERVER['HTTP_REFERER']);
	}
	
	public function level() {
		$this -> assign('levels', M('level') -> select());
		$this -> display();
	}
	
	public function level_edit() {
		if(IS_POST) {
			if(M('level') -> where('level_id = ' . $_POST['level_id']) -> save(array('price' => trim($_POST['price']), 'percent' => trim($_POST['percent'] * 0.01)))) {
				$this -> success('修改成功!', '/Admin/Index/level', 1);
				exit;
			} else {
				$this -> error('修改失败!');
				exit;
			}
		}
		$this -> assign('level', M('level') -> where('level_id = ' . I('get.level_id')) -> find());
		$this -> display();
	}
	
	public function check_top_up() {
		$logs = M('top_up_log');
		if(IS_POST) {
			$r = $logs -> where('log_id = ' . $_POST['log_id']) -> find();

			echo json_encode(array('code' => 0, 'message' => '审核成功!'));exit;
			echo json_encode(array('code' => -1, 'message' => '审核失败!'));exit;
		}
		$where = ' 1 = 1 ';
		if($_GET['start_time'] && $_GET['end_time']) {
			$where .= ' AND log_date >= ' . strtotime(trim($_GET['start_time'])) . ' AND log_date <= ' . strtotime(trim($_GET['end_time']));
			$logs -> where();
			$this->assign('start_time', $_GET['start_time']);
			$this->assign('end_time', $_GET['end_time']); 
		}

		$p = getpage($logs -> where($where) -> count(), 5);

		$this -> assign('active', array('', '注册币', '报单币'));
		$this -> assign('status', array('否','是'));
		$this -> assign('logs', $logs -> where($where) ->limit($p -> firstRow, $p -> listRows) -> order('log_is_state ASC') -> select());
		$this -> assign('page', $p->show());
		$this -> display();
	}
}